/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.sdt.datastructure;

import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import edu.yonsei.iwb.sdt.SDTLearner;
import edu.yonsei.iwb.sdt.ontology.PropertyArc;
import edu.yonsei.iwb.ts.TSSearch;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;

/**
 *
 * @author DK
 */
public class DataStore {
    private ArrayList<String> objectPropertyList;
    private ArrayList<String> datatypePropertyList;
    private Hashtable<String, PropertyArc> forwardPropertyArcSet = new Hashtable<String, PropertyArc>();
    private Hashtable<String, PropertyArc> backwardPropertyArcSet = new Hashtable<String, PropertyArc>();
    private Hashtable<String, ArrayList<String>> propertyAndSubjects = new Hashtable<String, ArrayList<String>>();
    private Hashtable<String, ArrayList<String>> propertyAndObjects = new Hashtable<String, ArrayList<String>>();
    
    public DataStore() throws IOException{
        objectPropertyList = TSSearch.listSubjectResource(RDF.type.getURI(), OWL.ObjectProperty.getURI());
        datatypePropertyList = TSSearch.listSubjectResource(RDF.type.getURI(), OWL.DatatypeProperty.getURI());
//        System.out.println(" ------ " + objectPropertyList.size());
        for (int i = 0; i < objectPropertyList.size(); i++) {
            String get = objectPropertyList.get(i);
//            System.out.println(" ---------------- " + get);
            
        }
        
        objectPropertyList.remove(SDTLearner.TARGETPROPERTY);
        datatypePropertyList.remove(SDTLearner.TARGETPROPERTY);
    }
    
    public boolean isExistInObjectPropertyList(String uri){
        return this.objectPropertyList.contains(uri);
    }
    
    public boolean isExistInDatatypePropertyList(String uri){
        return this.datatypePropertyList.contains(uri);
    }
    
    public void setPropertyArcSet(String uri, PropertyArc pa, boolean direction){
        if(direction){
            forwardPropertyArcSet.put(uri, pa);
        }else{
            backwardPropertyArcSet.put(uri, pa);            
        }        
    }
    
    public PropertyArc getPropertyArcByURI(String uri, boolean direction){
        if(direction){
            return forwardPropertyArcSet.get(uri);
        }else{
            return backwardPropertyArcSet.get(uri);
        }        
    }
    
    public boolean isExistPropertyArc(String uri, boolean direction){
        if(direction){
            return forwardPropertyArcSet.containsKey(uri);
        }else{
            return backwardPropertyArcSet.containsKey(uri);
        }
    }
    
    public void setConnectedSubjectsByProperty(String property, String subject){
        if(propertyAndSubjects.containsKey(property)){
            ArrayList<String> subjects = propertyAndSubjects.get(property);
            subjects.add(subject);
        }else{
            ArrayList<String> subjects = new ArrayList<String>();
            subjects.add(subject);
            propertyAndSubjects.put(property, subjects);
        }
    }
    
    public ArrayList<String> getConnectedSubjectsByProperty(String property){
        return propertyAndSubjects.get(property);
    }
    
    public void setConnectedObjectsByProperty(String property, String object){
        if(propertyAndObjects.containsKey(property)){
            ArrayList<String> objects = propertyAndObjects.get(property);
            objects.add(object);
        }else{
            ArrayList<String> objects = new ArrayList<String>();
            objects.add(object);
            propertyAndObjects.put(property, objects);
        }
    }
    
    public ArrayList<String> getConnectedObjectsByProperty(String property){
        return propertyAndObjects.get(property);
    }
    
}
